﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
	<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
		<Setter Property="SnapsToDevicePixels" Value="true"/>
		<Setter Property="Template" Value="{DynamicResource ComboBoxControlTemplate}"/>
		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
		<Setter Property="ItemContainerStyle" Value="{DynamicResource ComboBoxItemStyle}"/>
	</Style>
	<ControlTemplate x:Key="ComboBoxControlTemplate" TargetType="{x:Type ComboBox}">
		<Grid>
			<!-- The ToggleButton is databound to the ComboBox itself to toggle IsDropDownOpen -->
			<ToggleButton  x:Name="ToggleButton" 
                           Grid.Column="2" 
                           Template="{DynamicResource ToggleButtonControlTemplate}" 
                           Focusable="false" 
                           IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
                           ClickMode="Press"/>
			<ContentPresenter HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>
						
			<!-- The TextBox must be named PART_EditableTextBox or ComboBox will not recognize it -->
			<TextBox  x:Name="PART_EditableTextBox"
                      Visibility="Hidden" 
                      Template="{DynamicResource ComboBoxTextBox}" 
                      HorizontalAlignment="Left" 
                      Margin="3,3,23,3" 
                      Style="{x:Null}" 
                      VerticalAlignment="Center" 
                      Focusable="True" 
                      Background="Transparent" 
                      IsReadOnly="{TemplateBinding IsReadOnly}"/>
						
			<!-- The Popup shows the list of items in the ComboBox. IsOpen is databound to IsDropDownOpen which is toggled via the ComboBoxToggleButton -->
			<Popup x:Name="Popup"
                   IsOpen="{TemplateBinding IsDropDownOpen}" 
                   Placement="Bottom" 
                   Focusable="False" 
                   AllowsTransparency="True" 
                   PopupAnimation="Slide">
				<Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
					<Border x:Name="DropDownBorder" Background="{DynamicResource BrushControlBackgroundLight}" BorderBrush="{DynamicResource ImpassiveColor4}" BorderThickness="1" CornerRadius="0,0,3,3"/>
					<ScrollViewer Margin="4,6,4,6" Style="{DynamicResource ComboBoxScrollViewerStyle}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
							
						<!-- The StackPanel is used to display the children by setting IsItemsHost to be True -->
						<!--<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/>-->
                        <VirtualizingStackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" />
								
					</ScrollViewer>
				</Grid>
			</Popup>
		</Grid>
		<ControlTemplate.Triggers>						
			<!-- This forces the DropDown to have a minimum size if it is empty -->
			<Trigger Property="HasItems" Value="false">
				<Setter Property="MinHeight" Value="95" TargetName="DropDownBorder"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
			</Trigger>
			<Trigger Property="IsGrouping" Value="true">
				<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
			</Trigger>
			<Trigger Property="AllowsTransparency" SourceName="Popup" Value="true">
				<Setter Property="CornerRadius" Value="4" TargetName="DropDownBorder"/>
				<Setter Property="Margin" Value="0,2,0,0" TargetName="DropDownBorder"/>
			</Trigger>
			<Trigger Property="IsEditable" Value="true">
				<Setter Property="IsTabStop" Value="false"/>
				<Setter Property="Visibility" Value="Visible" TargetName="PART_EditableTextBox"/>
				<Setter Property="Visibility" Value="Hidden" TargetName="ContentSite"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	<ControlTemplate x:Key="ToggleButtonControlTemplate" TargetType="{x:Type ToggleButton}">
		<Grid>
			<Grid.ColumnDefinitions>
				<ColumnDefinition/>
				<ColumnDefinition Width="20"/>
			</Grid.ColumnDefinitions>
			<Border HorizontalAlignment="Stretch" Width="Auto" BorderBrush="{DynamicResource ImpassiveColor4}" Background="{DynamicResource BrushControlBackgroundLight}" BorderThickness="1,1,0,1" CornerRadius="3,0,0,3"/>
			<Grid Grid.Column="1">
				<Grid.RowDefinitions>
					<RowDefinition Height="0.514*"/>
					<RowDefinition Height="0.486*"/>
				</Grid.RowDefinitions>
				<Border BorderBrush="{DynamicResource ImpassiveColor4}" Grid.RowSpan="2" CornerRadius="0,3,3,0" BorderThickness="{DynamicResource ThicknessSize_1}" x:Name="border">
					<Border.Background>
						<LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
							<GradientStop Color="#FFA7BAA0" Offset="0"/>
							<GradientStop Color="#FFD0DECB" Offset="1"/>
						</LinearGradientBrush>
					</Border.Background>
				</Border>
				<Border Grid.RowSpan="1" BorderBrush="{DynamicResource ImpassiveColor4}" BorderThickness="1,1,1,0" Background="#33FFFFFF" CornerRadius="0,3,0,0"/>
			</Grid>
			<Path Grid.Column="1" HorizontalAlignment="Center" x:Name="Arrow" VerticalAlignment="Center" Fill="{DynamicResource GlyphBrush}" Data="M 0 0 L 4 4 L 8 0 Z"/>
		</Grid>
		<ControlTemplate.Triggers>
			<Trigger Property="IsMouseOver" Value="True">
				<Setter Property="Background" TargetName="border" Value="{DynamicResource BrushControlBackgroundLightFocused}"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	<Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
		<Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
		<Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
		<Setter Property="Padding" Value="3,0,3,0"/>
		<Setter Property="Background" Value="Transparent"/>
		<Setter Property="Template" Value="{DynamicResource ComboBoxItemControlTemplate}"/>
		<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
	</Style>
	<ControlTemplate x:Key="ComboBoxItemControlTemplate" TargetType="{x:Type ComboBoxItem}">
		<Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" CornerRadius="{DynamicResource CornerRadiusSmall}">
			<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
		</Border>
		<ControlTemplate.Triggers>
			<Trigger Property="IsHighlighted" Value="true">
				<Setter Property="Foreground" Value="#FF000000"/>
				<Setter Property="Background" TargetName="Bd" Value="#4CFFFFFF"/>
			</Trigger>
			<Trigger Property="IsEnabled" Value="false">
				<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
			</Trigger>
		</ControlTemplate.Triggers>
	</ControlTemplate>
	<Style x:Key="ComboBoxScrollViewerStyle" TargetType="{x:Type ScrollViewer}" BasedOn="{x:Null}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type ScrollViewer}">
					<Grid Background="{TemplateBinding Background}">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="*"/>
							<ColumnDefinition Width="Auto"/>
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="*"/>
							<RowDefinition Height="Auto"/>
						</Grid.RowDefinitions>
						<ScrollContentPresenter Grid.Column="0" Grid.Row="0" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" CanContentScroll="{TemplateBinding CanContentScroll}"/>
						
						<!-- The visibility of the ScrollBars is controlled by the implementation fo the control -->
						<ScrollBar Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Grid.Column="0" Grid.Row="1" x:Name="PART_HorizontalScrollBar" Style="{DynamicResource ScrollBarStyle}" Orientation="Horizontal" Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}" Minimum="0" Maximum="{TemplateBinding ScrollableWidth}" AutomationProperties.AutomationId="HorizontalScrollBar"/>
						<ScrollBar Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Grid.Column="1" Grid.Row="0" x:Name="PART_VerticalScrollBar" Style="{DynamicResource ScrollBarStyle}" Orientation="Vertical" Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}" Minimum="0" Maximum="{TemplateBinding ScrollableHeight}" AutomationProperties.AutomationId="VerticalScrollBar"/>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<!-- Resource dictionary entries should be defined here. -->
</ResourceDictionary>